package com.help10000.rms

import android.app.ActivityManager
import android.content.Context
import com.amir.common.BaseApplication
import com.amir.common.utils.Constant
import com.amir.common.utils.LogUtils
import com.amir.common.utils.SPUtils
import com.help10000.rms.common.App
import com.help10000.rms.ui.utils.ImageCompressor


class MyApplication : BaseApplication() {
    override fun onCreate() {
        super.onCreate()
        LogUtils.setDebug(BuildConfig.DEBUG)
        SPUtils.instance(this) // 必须放在所有 SPUtils 操作之前
        var readSplash = SPUtils.getBoolean(Constant.read_splash)
        if (readSplash) {
            if ("com.help10000.rms" == getProcessName(
                    this, android.os.Process.myPid()
                )
            ) {
                App.init(this)
                ImageCompressor.clearCompressedImages(this)
            }
        }

    }

    /**
     * 获取进程名
     */
    private fun getProcessName(cxt: Context, pid: Int): String {
        //获取ActivityManager对象
        val am = cxt.getSystemService(Context.ACTIVITY_SERVICE)
        if (am is ActivityManager) {
            //在运行的进程
            val runningApps = am.runningAppProcesses
            for (processInfo in runningApps) {
                if (processInfo.pid == pid) {
                    return processInfo.processName
                }
            }
        }
        return ""
    }


}